#ifndef MAPADAPTER_H
#define MAPADAPTER_H

#include <QObject>
#include <QSize>
#include <QPoint>
#include <QPointF>
#include <QLocale>
#include <QDebug>
#include <cmath>

class MapAdapter : public QObject
{
    friend class Layer;

    Q_OBJECT

public:
    virtual ~MapAdapter();

    //! returns the host of this MapAdapter
    /*!
         * @return  the host of this MapAdapter
         */
    QString host() const;

    //! returns the size of the tiles
    /*!
         * @return the size of the tiles
         */
    int tilesize() const;

    //! returns the min zoom value
    /*!
         * @return the min zoom value
         */
    int minZoom() const;

    //! returns the max zoom value
    /*!
         * @return the max zoom value
         */
    int maxZoom() const;

    //! returns the current zoom
    /*!
         * @return the current zoom
         */
    int currentZoom() const;

    virtual int adaptedZoom()const;

    //! translates a world coordinate to display coordinate
    /*!
         * The calculations also needs the current zoom. The current zoom is managed by the MapAdapter, so this is no problem.
         * To divide model from view the current zoom should be moved to the layers.
         * @param  coordinate the world coordinate
         * @return the display coordinate (in widget coordinates)
         */
    virtual QPoint coordinateToDisplay(const QPointF& coordinate) const = 0;

    //! translates display coordinate to world coordinate
    /*!
         * The calculations also needs the current zoom. The current zoom is managed by the MapAdapter, so this is no problem.
         * To divide model from view the current zoom should be moved to the layers.
         * @param  point the display coordinate
         * @return the world coordinate
         */
    virtual QPointF	displayToCoordinate(const QPoint& point) const = 0;

protected:
    MapAdapter(const QString& host, const QString& serverPath, int tilesize, int minZoom = 0, int maxZoom = 0);
    virtual void zoom_in() = 0;
    virtual void zoom_out() = 0;
    virtual bool isValid(int x, int y, int z) const = 0;
    virtual QString query(int x, int y, int z) const = 0;

    QSize 	size;
    QString	myhost;
    QString	serverPath;
    int mytilesize;
    int min_zoom;
    int max_zoom;
    int current_zoom;

    int param1;
    int param2;
    int param3;
    int param4;
    int param5;
    int param6;

    QString sub1;
    QString sub2;
    QString sub3;
    QString sub4;
    QString sub5;
    QString sub6;

    int order[3][2];

    int middle_x;
    int middle_y;

    qreal numberOfTiles;
    QLocale loc;
};

#endif
